<%@ page import="java.util.List" %>
<%@ page import="com.fduss.artStore.entity.Order" %>
<%@ page import="com.fduss.artStore.entity.OrderDetail" %>
<%@ page import="com.fduss.artStore.entity.Artwork" %><%--
  Created by IntelliJ IDEA.
  User: duocai wu
  Date: 2017/7/1
  Time: 17:25
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">
    <%--<link rel="icon" href="../../favicon.ico">--%>

    <title>Profile</title>

    <!-- Bootstrap core CSS -->
    <link href="./css/bootstrap.min.css" rel="stylesheet">
    <style>
        .margin-top-100 {
            margin-top: 100px;
        }
    </style>
</head>
<body>
<jsp:useBean id="artworkService" scope="session" class="com.fduss.artStore.service.impl.ArtworkServiceImpl"/>
    <jsp:useBean id="orderService" scope="session" class="com.fduss.artStore.service.impl.OrderServiceImpl" />
    <%
        Customer customer = (Customer) session.getAttribute("user");
        if (customer == null)
            response.sendRedirect("./loginPage.jsp");
        assert customer != null;
        List<Order> completed = orderService.getCompletedOrders(customer.getCustomerId());
        List<Order> notCompleted = orderService.getNotCompletedOrders(customer.getCustomerId());
    %>


    <%@include file="header.jsp"%>

    <div class="margin-top-100"></div>
    <div class="container">
        <!-- Nav tabs -->
        <ul class="nav nav-tabs" id="myTabs" role="tablist">
            <li role="presentation"><a href="#Profile" aria-controls="Profile" role="tab" data-toggle="tab">Profile</a></li>
            <li role="presentation"><a href="#Cart" aria-controls="Cart" role="tab" data-toggle="tab">Cart</a></li>
            <li role="presentation"><a href="#Records" aria-controls="Records" role="tab" data-toggle="tab">Records</a></li>
            <li role="presentation"><a href="#Settings" aria-controls="Settings" role="tab" data-toggle="tab">Settings</a></li>
        </ul>

        <!-- Tab panes -->
        <div class="tab-content">
            <div role="tabpanel" class="tab-pane" id="Profile">
                <table class="table">
                    <tr>
                        <td>UserName</td>
                        <td><%=customer.getCustomerLogon().getUserName()%></td>
                    </tr>
                    <tr>
                        <td>Name</td>
                        <td><%=customer.getFirstName() + " " + customer.getLastName()%></td>
                    </tr>
                    <tr>
                        <td>Address</td>
                        <td><%=customer.getAddress()%></td>
                    </tr>
                    <tr>
                        <td>City</td>
                        <td><%=customer.getCity()%></td>
                    </tr>
                    <tr>
                        <td>Country</td>
                        <td><%=customer.getCountry()%></td>
                    </tr>
                    <tr>
                        <td>Postal</td>
                        <td><%=customer.getPostal()%></td>
                    </tr>
                    <tr>
                        <td>Phone</td>
                        <td><%=customer.getPhone()%></td>
                    </tr>
                    <tr>
                        <td>Email</td>
                        <td><%=customer.getEmail()%></td>
                    </tr>
                </table>
            </div>
            <div role="tabpanel" class="tab-pane" id="Cart">
                <form action="./pay" method="post">
                    <table class="table">
                        <tr>
                            <td>select</td><td>OrderId</td><td>DateCreate</td><td>Artwork</td>
                            <td>Frame</td><td>Matt</td><td>Glass</td>
                        </tr>
                            <%
                                for (Order order : notCompleted) {
                                    OrderDetail orderDetail = orderService.getOrderDetail(order.getOrderId());
                                    Artwork artwork = artworkService.getOne(orderDetail.getArtworkID());
                            %>
                            <tr>
                                <td>
                                    <input type="checkbox" name="orders" value="<%=order.getOrderId()%>" aria-label="...">
                                </td>
                                <td><%=order.getOrderId()%></td>
                                <td><%=order.getDateCreated()%></td>
                                <td><a href="./artworkDetail.jsp?id=<%=artwork.getArtWorkId()%>"><%=artwork.getTitle()%></a></td>
                                <td><%=orderDetail.getFrame()!=null?orderDetail.getFrame().getTitle():""%></td>
                                <td><%=orderDetail.getMatt()!=null?orderDetail.getMatt().getTitle():""%></td>
                                <td><%=orderDetail.getGlass()!=null?orderDetail.getGlass().getTitle():""%></td>
                            </tr>
                            <%}%>
                    </table>
                    <div class="text-center">
                        <button type="submit" class="btn btn-lg btn-primary" role="button">Pay</button>
                        &nbsp;&nbsp;&nbsp;&nbsp;
                        <button type="button" class="btn btn-lg btn-primary" role="button">Cancel</button>
                    </div>
                </form>
            </div>
            <div role="tabpanel" class="tab-pane" id="Records">
                <table class="table">
                    <tr>
                        <td>OrderId</td><td>DateCreate</td><td>DateCompleted</td><td>Artwork</td>
                        <td>Frame</td><td>Matt</td><td>Glass</td>
                    </tr>
                    <%
                        for (Order order : completed) {
                            OrderDetail orderDetail = orderService.getOrderDetail(order.getOrderId());
                            Artwork artwork = artworkService.getOne(orderDetail.getArtworkID());
                    %>
                        <tr>
                            <td><%=order.getOrderId()%></td>
                            <td><%=order.getDateCreated()%></td>
                            <td><%=order.getDateCompleted()%></td>
                            <td><a href="./artworkDetail.jsp?id=<%=artwork.getArtWorkId()%>"><%=artwork.getTitle()%></a></td>
                            <td><%=orderDetail.getFrame()!=null?orderDetail.getFrame().getTitle():""%></td>
                            <td><%=orderDetail.getMatt()!=null?orderDetail.getMatt().getTitle():""%></td>
                            <td><%=orderDetail.getGlass()!=null?orderDetail.getGlass().getTitle():""%></td>
                        </tr>
                    <%}%>
                </table>
            </div>
            <div role="tabpanel" class="tab-pane" id="Settings">

            </div>
        </div>
    </div>
    <!-- Bootstrap core JavaScript
        ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

    <script>
        $('#myTabs a').click(function (e) {
            e.preventDefault();
            $(this).tab('show');
        });
        var loc = window.location.href;
        var index = loc.indexOf('#');
        $('#myTabs').find('a[href="'+loc.substring(index)+'"]').tab("show");
    </script>
</body>
</html>
